package de.koller.density.render;

import de.koller.aframe.gl.ATexture;
import de.koller.aframe.gl.obj.Quad;
import de.koller.density.DNode;
import org.lwjgl.opengl.GL11;

public class DRender extends DNode {
	
	private ATexture grid = new CircleTexture();
	private Quad floor = Quad.createZPlane( -2, 0, -2, 4, 4 ).setTextureLayout( 16, 16 );
	
	@Override
	protected void init() {
		super.init();
		
//		GL11.glEnable( GL11.GL_CULL_FACE );
//		GL11.glCullFace( GL11.GL_BACK );

		GL11.glEnable( GL11.GL_DEPTH_TEST );
		GL11.glDepthFunc( GL11.GL_LEQUAL );
		
		GL11.glAlphaFunc( GL11.GL_GREATER, 0.01f );
		GL11.glEnable( GL11.GL_ALPHA_TEST );
	}
	
	private void isometricSet() {
		GL11.glMatrixMode( GL11.GL_PROJECTION );
		GL11.glLoadIdentity();

		GL11.glOrtho( -4f/3f, 4f/3f, -1f, 1f, -1000, 1000 );
		
		GL11.glMatrixMode( GL11.GL_MODELVIEW );
		GL11.glLoadIdentity();
		
		GL11.glRotatef( 35.264f, 1, 0, 0 );
		GL11.glRotatef( 45, 0, 1, 0 );
	}
	
	public void renderGame( int elapsedTime ) {		
		isometricSet();
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
		GL11.glColor3f( 1, 1, 1 );
		
		grid.bindMipMap();
		floor.renderStructure();
	}
	
}
